package com.opengroupe.activity;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.opengroupe.R;
import com.opengroupe.database.qRHSQLiteHelper;

public class MenuActivity extends Activity {
	
	private Button btnCreerCandidat;
	private Button btnConsulterResultat;
	private Button btnGererQuestionnaire;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        
        btnCreerCandidat = (Button)findViewById(R.id.btnCreationCandidat);
        btnCreerCandidat.setOnClickListener(creerCandidatListener);
        
        btnConsulterResultat = (Button)findViewById(R.id.btnConsulterResultat);
        btnConsulterResultat.setOnClickListener(consulterResultatListener);

        btnGererQuestionnaire = (Button)findViewById(R.id.btnGererQuestionnaire);
        btnGererQuestionnaire.setOnClickListener(gererQuestionnaireListener);

        
        
        Button btnDeconnecter = (Button)findViewById(R.id.btnDeconnecter);
        btnDeconnecter.setOnClickListener(new OnClickListener(){
        	public void onClick(View v) {
        		Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
    			startActivityForResult(intent, 0);
    		}
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_menu, menu);
        return true;
    }
    
    
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
	    if (keyCode == KeyEvent.KEYCODE_BACK) {
	    	finish();
	    }
	    return super.onKeyDown(keyCode, event);
	}

    
    private OnClickListener creerCandidatListener = new OnClickListener() {

		public void onClick(View v) {
			Intent intent = new Intent(getApplicationContext(), CreateCandidatActivity.class);
			startActivityForResult(intent, 0);
			finish();
		}
    };
    
    private OnClickListener consulterResultatListener =  new OnClickListener() {

		public void onClick(View v) {
			Intent intent = new Intent(getApplicationContext(), ConsulterResultatActivity.class);
			startActivityForResult(intent, 0);
		}
    };
    
    private OnClickListener gererQuestionnaireListener =  new OnClickListener() {

		public void onClick(View v) {
			
			Log.i("MenuActivity","gererQuestionnaireListener - onClick");
			
			Intent intent = new Intent(getApplicationContext(), GererQuestionnaireActivity.class);
			
			Log.i("MenuActivity","gererQuestionnaireListener - onClick, startActivityForResult");
			
			startActivityForResult(intent, 0);
		}
    };
}